<?

	require_once '_scriptfile.php';

	class Fmgr0v0r01_htaccess extends Fmgr0v0r01__scriptfile{
	
		var $media_class = 'Apache Environment Settings';
	
		protected $rules;
		
		function root_write(){
			return usr()->can_apache;
		}
		
		function is_writable(){
			return usr()->can_apache;
		}
		
		function is_script(){
			return false;	
		}
		
		function is_parsed(){
			return false;	
		}
		
		function contents(){
			if(!$this->allow_read) return;
			return file_get_contents($this->realpath());	
		}
		
		function put(){
			return false;	
		}
		
		function rules(){
			if(is_null($this->rules)){
				$this->rules = new htrules;
				$c = $this->contents();
				if(preg_match_all('/SetEnv\s+SMUOI_([A-Z]+)\s+\"?\[?\s*([^\"\]\n]+)\s*\]?\"?/i', $c, $m)){
					$a = array();
					for($i = 0; $i<count($m[1]); $i++){
						$e = $m[1][$i];
						foreach(smuoi_explode(',', $m[2][$i]) as $x) $a[$e][$x] = true;
					}			
					$this->rules->set($a);
				}
			}
			return $this->rules;
		}
		
		protected function set_basename($b){
			if(!$this->is_draft()) return false;
			return parent::set_basename($b);	
		}
		
		protected function set_par(Fmgr_Directory $newpar){
			$oldpar = $this->parent();
			if(!parent::set_par($newpar)) return false;
			$oldpar->htaccess = '';
			return true;
		}
		
		function copy_to(Fmgr_Directory $par, $lnks=true){
			if(($par === $this->parent()) && (!$this->is_draft())) return false;
			return parent::copy_to($par, $lnks);
		}
		
		protected function run_sanity_checks(){
			parent::run_sanity_checks();
			$this->parent()->htaccess = $this;
			$this->commit_parent();
		}
		
		function destroy(){
			if(!parent::destroy()) return false;
			$this->parent()->htaccess = '';
			$this->commit_parent();
			return true;
		}
	
	}
	
?>